package com.unicom.fragment;

import java.util.ArrayList;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.unicom.adapter.AllStoryAdapter;
import com.unicom.config.StoryCore;
import com.unicom.model.StoryModel;
import com.unicom.mystory.R;
import com.unicom.network.task.TaskGetComment;
import com.unicom.response.CommentModel;
import com.unicom.utils.StoryListener;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class AllStoryFragment extends Fragment{
	private PullToRefreshListView lvStory;
	private ArrayList<StoryModel> listStory = new ArrayList<StoryModel>();
	private AllStoryAdapter adapter;
	AllStoryListener listener = new AllStoryListener();
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.allstory_layout_fragment, container,false);
		lvStory = (PullToRefreshListView) view.findViewById(R.id.list_story);
		StoryModel item  = new StoryModel("1", "", "ai cho toi tinh yeu", "hoang van kien", 10, 10, 3);
		StoryModel item1 = new StoryModel("1", "", "ai cho toi tinh yeu", "hoang van kien", 10, 10, 3);
		StoryModel item2 = new StoryModel("1", "", "ai cho toi tinh yeu", "hoang van kien", 10, 10, 3);
		StoryModel item3 = new StoryModel("1", "", "ai cho toi tinh yeu", "hoang van kien", 10, 10, 3);
		StoryModel item4 = new StoryModel("1", "", "ai cho toi tinh yeu", "hoang van kien", 10, 10, 3);
		listStory.clear();
		listStory.add(item);
		listStory.add(item1);
		listStory.add(item2);
		listStory.add(item3);
		listStory.add(item4);
		AllStoryAdapter adapter = new AllStoryAdapter(listStory, getActivity());
		lvStory.setAdapter(adapter);
		//lay data authenKey được lấy bên BMS mỗi lần đăng nhập cần một authenKey khác
		StoryCore.getInstance(getActivity()).taskGetComment("93581a97d3c45f77930e61cd4cd3677c", "758", "10", "1", listener);
		
		return view;
	}
	
	class AllStoryListener extends StoryListener{
		@Override
		public void finishGetComment(int returnCode, String resultMsg,int recordNumber, int countPage,ArrayList<CommentModel> listComment) {
			super.finishGetComment(returnCode, resultMsg, recordNumber, countPage,listComment);
		}
	} 
}
